<?php

namespace app\admin\controller\business;

use app\common\controller\Backend;

//私海
class Privateseadetail extends Backend
{

  // 当前对象模型
  protected $model = null;

  public function _initialize()
  {
    parent::_initialize();
    $this->BusinessModel = model('Business.Business');
    $this->VisitModel = model('Business.Visit');
    // $this->AdminModel = model('Admin');
    // $this->ReceiveModel = model('Business.Receive');
    // $this->SourceModel = model('Business.Source');

    //性别选项
    // $this->genderoption = ["0" => '保密', '1' => '男', '2' => '女'];
    // $this->assign('genderoption', $genderoption);
  }


  public function index($ids = null)
  {
    $adminid  = $this->auth->id; //管理员id

    $row = $this->BusinessModel
      ->alias('business')
      ->where(['adminid' => $adminid, 'business.id' => $ids])
      ->with('source')
      ->find();
    if (!$row) {
      $this->error('客户不存在，请重新选择');
    }
    $this->assign('row', $row);
    return $this->view->fetch();
  }



  public function visit($ids = null)
  {
    $business = $this->BusinessModel->where('id', $ids)->select();
    if (!$business) {
      $this->error('客户不存在');
    }

    if ($this->request->isAjax()) {
      return json($business);
    }
    // 客户信息
    $info = [
      'nickname' => $business['nickname'], //客户
      'mobile' => $business['mobile'], //客户联系方式
      'email' => $business['email'], //邮箱
      'gender_text' => $business['gender_text'], //性别
      'source_name' => $business['source']['name'], //客户来源
      'deal_text' => $business['deal_text'], //成交状态
      'address' => '', //地区
      'auth_text' => '', //认证状态
      'createtime' => '', //创建时间
      'avatar' => '',
    ];

    $this->assign('row', $info);
    return $this->view->fetch();
  }


  public function receive($ids = null)
  {
    $business = $this->VisitModel->select();
    $this->success('', '', $business);

    /*    var_dump($business);
    exit; */
    /*  if (!$business) {
      $this->error('客户不存在');
    } */

    /*  // 客户信息
    $info = [
      'nickname' => $business['nickname'], //客户
      'mobile' => $business['mobile'], //客户联系方式
      'email' => $business['email'], //邮箱
      'gender_text' => $business['gender_text'], //性别
      'source_name' => $business['source']['name'], //客户来源
      'deal_text' => $business['deal_text'], //成交状态
      'address' => '', //地区
      'auth_text' => '', //认证状态
      'createtime' => '', //创建时间
      'avatar' => '',
    ]; */

    $this->assign('row', $business);
    // return $this->view->fetch();
  }
}
